<template>
    <div class="ui form">
        <h4 class="ui header">预定服务信息</h4>
        <mybind :field='spField' @setVo='setSpid'></mybind>
        <div class="inline fields">
            <label>需要预定时间？</label>
            <div class="field">
                <div class="ui radio checkbox">
                    <input type="radio" value="1" v-model='pageData.need_target_date'>
                    <label>是</label>
                </div>
            </div>
            <div class="field">
                <div class="ui radio checkbox">
                    <input type="radio" value="0" v-model='pageData.need_target_date'>
                    <label>否</label>
                </div>
            </div>
        </div>

        <div class=" wide fields inline" :class="{disabled:pageData.need_target_date==0}">
            <label>最晚提前预定时间:</label>
            <div class="field">
                <select class="ui fluid search dropdown" v-model="pageData.preset_time[0]">
                    <option v-for='item in presetTimeDayList' :value="item">{{item}}</option>
                </select><span>天</span>
            </div>
            <div class="field">
                <select class="ui fluid search dropdown" v-model="pageData.preset_time[1]">
                    <option v-for='item in presetTimeHourList' :value="item">{{`${(item + 100).toString().slice(1)}:00`}}</option>
                </select>
            </div>
        </div>

        <!-- <h4 class="ui header">预定确认时间</h4>
        <div class="inline fields">
            <label>确认时间</label>
            <div class="field inline">
                <select class="ui fluid search dropdown" v-model="pageData.confirm_time">
                    <option v-for='item in confirmTimeList' :value="item">{{item}}</option>
                </select><span>小时</span>
            </div>
            <label>周末时间：</label>
            <div class="field">
                <div class="ui radio checkbox">
                    <input type="radio" value='1' v-model='pageData.weekend_work'>
                    <label>是</label>
                </div>
            </div>
            <div class="field">
                <div class="ui radio checkbox">
                    <input type="radio" value='0' v-model='pageData.weekend_work'>
                    <label>否</label>
                </div>
            </div>


            <label>节假日工作：</label>
            <div class="field">
                <div class="ui radio checkbox">
                    <input type="radio" value='1' v-model='pageData.holiday_work'>
                    <label>是</label>
                </div>
            </div>
            <div class="field">
                <div class="ui radio checkbox">
                    <input type="radio" value='0' v-model='pageData.holiday_work'>
                    <label>否</label>
                </div>
            </div>
        </div> -->

        <h4 class="ui header">预定限制</h4>
        <div class="field inline">
            <label>是否需要联系人：</label>
            <div class="ui radio checkbox">
                <input type="radio" value='1' v-model='pageData.need_contact'>
                <label>需要</label>
            </div>
            <div class="ui radio checkbox">
                <input type="radio" value='0' v-model='pageData.need_contact'>
                <label>不需要</label>
            </div>
        </div>
        <div class="field inline">
            <label>旅客信息：</label>
            <div class="ui radio checkbox">
                <input type="radio" value='1' v-model='pageData.need_guest_info'>
                <label>需要</label>
            </div>
            <div class="ui radio checkbox">
                <input type="radio" value='0' v-model='pageData.need_guest_info'>
                <label>不需要</label>
            </div>
        </div>
        <template v-if='pageData.need_guest_info==1'>
            <div class="fields inline">
                <label>证件类型</label>
                <div class="field" v-for='item in identityTypeList'>
                    <div class="ui checkbox">
                        <input type="checkbox" :value='item.value' v-model='pageData.identity_type'>
                        <label>{{item.label}}</label>
                    </div>
                </div>
            </div>
            <div class="fields inline">
                <label>份数限制：</label>
                <div class="field">
                    <div class="ui radio checkbox">
                        <input type="radio" v-model='pageData.buy_total_limt' value='1'>
                        <label>是</label>
                    </div>
                </div>
                <div class='field' :class='{disabled:pageData.buy_total_limt==0}'>
                    <input type="number" v-model='pageData.buy_total_limt_quantity'>
                </div>
                <div class="field">
                    <div class="ui radio checkbox">
                        <input type="radio" v-model='pageData.buy_total_limt' value='0'>
                        <label>否</label>
                    </div>
                </div>
            </div>
        </template>

        <mybind :field='deliveryField' @setVo='setDeliveryid'></mybind>

<div class="field ">
    <label>核单地址</label>
    <input type="text" v-model='pageData.collect_address'>
</div>

        <div class="field inline">
            <label>自动发货：</label>
            <div class="ui radio checkbox">
                <input type="radio" value="1" v-model='pageData.auto_delivery'>
                <label>是</label>
            </div>
            <div class="ui radio checkbox">
                <input type="radio" value="0" v-model='pageData.auto_delivery'>
                <label>否</label>
            </div>
        </div>


        <div class="field inline">
            <label>退款类型:</label>
            <select class="ui fluid search dropdown" v-model="pageData.refund_rule">
                <option v-for='item in refundRuleList' :value="item.value">{{item.label}}</option>
            </select>
        </div>
        <h4 class="ui header">服务信息</h4>
        <div class="field">
            <label>短信模板</label>
            <textarea v-model='pageData.msg_model'></textarea>
        </div>
        <div class="field">
            <label>商品备注</label>
            <textarea v-model='pageData.product_remark'></textarea>
        </div>
    </div>
</template>
<script>
    import tool from 'src/util/tool';
    import util from '_util/index';
    import logic from '_logic';

    import mybind from '../../field/bind'

    export default {
        data() {
            return {
                val: null,
                vo: {},
                spField: {
                    title: '供应商',
                    data_type: 0,
                    name: 'sp_id',
                    bind_name_field: 'supplier_name',
                    bind_param: 'type=2&isSearch=1',
                    bindModel: 15,
                    fval: '',
                },
                deliveryField: {
                    title: '配送方式',
                    data_type: 0,
                    name: 'delivery_group',
                    bind_name_field: 'delivery_group_name',
                    bindModel: 33,
                    fval: '',
                },
                identityTypeList: [{value: 1, label: '身份证'},
                    {value: 2, label: '驾驶证'},
                    {value: 3, label: '军官证'},
                    {value: 4, label: '护照'},
                    {value: 5, label: '手机号'}],
                refundRuleList: [
                    {value: 1, label: "按商品为单位全部退，无需审核（默认）"},
                    {value: 2, label: "以份数为单位部分退，无需审核"},
                    {value: 3, label: "按商品为单位全部退，需审核"},
                    {value: 4, label: "以份数为单位部分退，需审核"},
                    {value: 5, label: "不允许退单"}
                ],
                pageData: {
                    sp_id: {value:'',is_must:true,label:'供应商信息'},
                    //delivery_id:"",
                    need_target_date: 0,
                    preset_time: ['', ''],
                    collect_address:'',
                    confirm_time: 1,
                    weekend_work: 1,
                    holiday_work: 1,
                    need_contact: 0,
                    need_guest_info: 0,
                    identity_type: [],
                    buy_total_limt: 0,
                    buy_total_limt_quantity: 1,
                    auto_delivery: 0,
                    refund_rule: 1,
                    msg_model:'',
                    product_remark:'',
                }
            }
        },
        components: {
            mybind
        },
    watch:{
            pageData:{
                handler(){
                  this.$emit("onchange", {name: 4, data: this.pageData});
                },
                deep:true
            },
			'pageData.buy_total_limt_quantity':function(newVal,oldVal){
				if(newVal<1){
					this.pageData.buy_total_limt_quantity = 1
				}
			}
        },
        methods: {
            setSpid(sp, id, name){
                this.pageData.sp_id.value = id;
                if(name){
                  util.store.commit(this,'setEditVoContact', {supplier_name:name})
                }
            },
            setDeliveryid(sp, id, name){
                this.pageData.delivery_id = id
            }
        },
        computed: {
            pageFilterData(){
                let data = this.pageData;
                if(!data.need_target_date){delete data.preset_time}
                if(!data.need_guest_info){delete data.identity_type}
                if(!data.buy_total_limt){delete data.buy_total_limt_quantity}
                return data
            },
            presetTimeHourList(){
                let data = [];
                for (var i = 0; i < 24; i++) {
                    data.push(i)
                }
                ;
                return data
            },
            presetTimeDayList(){
                let data = [];
                for (var i = 0; i <= 10; i++) {
                    data.push(i)
                }
                ;
                return data
            },
            confirmTimeList(){
                let data = [];
                for (var i = 1; i <= 24; i++) {
                    data.push(i)
                }
                ;
                return data
            }
        },
        mounted() {

        },
        props: {
            disable: {
                default: true
            },
            params: {
                type: Object,
                default: function () {
                    return {}
                }
            }
        },
        created() {
          if(this.params.data[4]){
              this.spField.fval = this.params.data[4].sp_id.value;
              this.deliveryField.fval = this.params.data[4].delivery_id;
              this.pageData = {...this.pageData,...this.params.data[4]}
          }else{
              this.$emit("onchange", {name: 4, data: this.pageData});
          }
        },
        mounted(){

        }
    }
</script>
<style rel="stylesheet/less" scoped lang="less">@import "../../../common/style/mixin";

.inlineInput {
    display: inline-block;
}
</style>
